package com.zch.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.print.attribute.HashAttributeSet;

import com.base.dialect.PaginationSupport;
import com.base.dao.model.Ret;
import com.base.dao.model.Grid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.lang.StringUtils;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import com.base.action.CoreController;

import com.zch.dao.model.MyActivity;
import com.zch.dao.model.MyActivityExample;
import com.zch.daoEx.model.MyActivityEx;
import com.zch.service.MyActivityService;

@RequestMapping("myActivity")
@Controller
@LoginFilter
public class MyActivityController extends CoreController{

	@Autowired
	private MyActivityService myActivityService;

	@RequestMapping("/list")
	@ResponseBody
	public String list(Integer page, Integer rows){
		PaginationSupport.byPage(page, rows);
		MyActivityExample example = new MyActivityExample();
		List<MyActivity> list = myActivityService.selectByExample(example);
		return JSONUtils.serialize(new Grid(PaginationSupport.getContext().getTotalCount(), list));
	}

	@RequestMapping("/save")
	@ResponseBody
	public String save(MyActivity myActivity){
		if (StringUtils.isBlank(myActivity.getId())){
			myActivityService.insert(myActivity);
		}else{
			myActivityService.updateByPrimaryKeySelective(myActivity);
		}
		return JSONUtils.serialize(new Ret(0));
	}

	@RequestMapping("/findById")
	@ResponseBody
	public String find(String id){
		MyActivity myActivity = myActivityService.selectByPrimaryKey(id);
		return JSONUtils.serialize(myActivity);
	}

	@RequestMapping("/del")
	@ResponseBody
	public String del(String id){
		String[] ids = id.split(",");
		for (String str : ids){
			myActivityService.deleteByPrimaryKey(str);
		}
		return JSONUtils.serialize(new Ret(0));
	}
	@RequestMapping("/JoinList")
    @ResponseBody
    public String JoinList(Integer page, Integer rows, String name){
        PaginationSupport.byPage(page, rows);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", name);
        List<MyActivityEx> list =myActivityService.selectJoinList(map);
        return JSONUtils.serialize(new Grid(PaginationSupport.getContext().getTotalCount(), list));
    }
}